Conversions Methods
The Conversions object contains the following methods:
ConvertValue
The ConvertValue method converts the provided value from its source units to the destination units.
Syntax
ConvertValue(Value As Integer, UnitsSource As String, UnitsDestination As String) As String
Parameters
| Parameter | Required | Description |
|---|---|---|
|
Value |
Yes |
The original number to be converted. |
|
UnitsSource |
Yes |
The unit name that Value is in. |
|
UnitsDestination |
Yes |
The unit name that Value will be converted to. |
Remarks
Return Value: Value after it has been converted into UnitsDestination.
Example
The following method converts 9001 centimeters to meters.
Sub conValue()
Dim objConversion
Set objConversion = CreateObject("CxScript.Conversions")
Dim iRet, iValue, strSource, strDest
iValue = 9001
strSource = "cm"
strDest = "m"
iRet = objConversion.ConvertValue(ivlaue, strSource, strDest)
edtMessageBox.Text = iValue & strSource & " is equal to " & iRet & strDest
End Sub
GetAllCategories
The GetAllCategories method returns a list of all unit categories by their integer identifier. It does not return the category name string. GetCategoryName can be used in conjunction to get a human-readable name.
Syntax
GetAllCategories() As Variant
Remarks
Return Value: List of all unit categories by their integer identifier.
Example
The following example retrieves all unit category IDs, category names, units for each category, and the unit descriptions.
Dim objConversions
Set objConversions = CreateObject ("CxScript.Conversions")
' get all unit category IDs
Dim arrCategories
arrCategories = objConversions.GetAllCategories
Dim strUnit
Dim strUnitDesc
Dim arrUnits
Dim nCategory
Dim strCategoryName
For Each nCategory In arrCategories
' now that we have the ID for the category, get its name
strCategoryName = objConversions.GetCategoryName(nCategory)
' get the units for this category
arrUnits = objConversions.GetUnitsForCategory(nCategory)
For Each strUnit In arrUnits
strUnitDesc = objConversions.GetUnitDescription(strUnit)
' TODO: store category ID, category name, unit name, and unit description
Next
Next
GetAllUnitNames
The GetAllUnitNames method retrieves all valid unit names (optionally abbreviates them).
Syntax
GetAllUnitNames(Abbreviate As Boolean) As Variant
Parameters
| Parameter | Required | Description |
|---|---|---|
|
Abbreviate |
Yes |
Set to True to abbreviate all the unit names, False to return the full names. |
Remarks
Return Value: An array of all unit names.
Example
The following example gets the unabbreviated names of all units and displays them in a list box.
Sub getUnitNames()
Dim arrNames, item, objConversion
Set objConversion = CreateObject("CxScript.Conversions")
arrNames = objConversion.GetAllUnitNames(False)
For Each item In arrNames
lstUnits.AddString(item)
Next
End Sub
GetCategoryName
The GetGategoryName method returns the name for the provided unit category identifier.
Syntax
GetCategoryName(Category As Integer) As String
Parameters
| Parameter | Required | Description |
|---|---|---|
|
Category |
Yes |
The unit category name string. |
Remarks
Return Value: The human-readable name of the unit category.
Example
See the example for GetAllCategories.
GetConvertableUnitNames
The GetConvertableUnitNames method retrieves all unit names to which the provided unit name can be converted.
Syntax
GetConvertableUnitNames(Units As String, Abbreviate As Boolean) As Variant
Parameters
| Parameter | Required | Description |
|---|---|---|
|
Units |
Yes |
A valid unit name. |
|
Abbreviate |
Yes |
Set to True to abbreviate the unit names, False to return the full names. |
Remarks
Return Value: An array of all convertible unit names. If Units is invalid, an empty array is returned.
Example
The following example gets all the units that meters can be converted into.
Sub getConvertableNames()
Dim arrNames, item, objConversion
Set objConversion = CreateObject("CxScript.Conversions")
arrNames = objConversion.GetConvertableUnitNames("meters", False)
For Each item In arrNames
lstUnits.AddString(item)
Next
End Sub
GetUnitDescription
The GetUnitDescription method returns the long name for a given unit. For example, providing "m" will return "meters".
Syntax
GetUnitDescription(Unit As String) As String
Parameter
| Parameter | Required | Description |
|---|---|---|
|
Unit |
Yes |
The abbreviated unit. |
Remarks
Return Value: The long name of the given unit.
Example
See the example for GetAllCategories.
GetUnitsForCategory
The GetUnitsForCategory method returns a list of all units for the provided unit category. The unit name as a string will be in the returned array.
Syntax
GetUnitsForCategory(Category As Integer) As Variant
Parameter
| Parameter | Required | Description |
|---|---|---|
|
Category |
Yes |
The unit category name string. |
Remarks
Return Value: An array of all unit names.
Example
See the example for GetAllCategories.
IsConvertable
The IsConvertable method determines if there is a valid conversion between the provided unit names.
Syntax
IsConvertable(UnitsSource As String, UnitsDestination As String) As Boolean
Parameters
| Parameter | Required | Description |
|---|---|---|
|
UnitsSource |
Yes |
A valid unit name. The method will test if this parameter can be converted into UnitsDestination. |
|
UnitsDestination |
Yes |
This method will test if UnitsSource can be converted into this unit name. |
Remarks
Return Value: A Boolean indicating whether the two units are convertible.
Example
The following example checks if meters is convertible to kilometers.
Sub isConvertible()
Dim objConversion
Set objConversion = CreateObject("CxScript.Conversions")
Msgbox objConversion.isConvertable("meters", "kilometers") 'Returns True
End Sub
SetBarAirPressure
The SetBarAirPressure method overrides the conversion library’s default air pressure value used to convert from gauge to absolute pressure.
Syntax
SetBarAirPressure(BarAirPressure As Double)
Parameter
| Parameter | Required | Description |
|---|---|---|
|
BarAirPressure |
Yes |
The new value to set for air pressure. |
Example
The following example sets the barometric air pressure to 1.0132 bars.
Sub setBarPressure()
Dim objConversion
Set objConversion = CreateObject("CxScript.Conversions")
objConversion.SetBarAirPressure(1.01320)
edtMessageBox.Text = "Bar pressure set"
End Sub


